package main.java.indi.zyj.hot100;

import java.util.Arrays;

public class _03_longestConsecutive {
    public int longestConsecutive(int[] nums) {

        if (nums.length == 0){
            return 0;
        }

        Arrays.sort(nums);
        int max = 1, current = 1;

        for (int i = 1; i < nums.length; i++) {
            if (nums[i] - nums[i-1] == 1){
                current++;
            }else if (nums[i] != nums[i-1]){
                current = 1;
            }
            max = Math.max(max, current);
        }

        return max;
    }
}
